#ifndef ALGORITHMHANDLER_H
#define  ALGORITHMHANDLER_H
#include "GlobalHeader.h"
#include "NodePoint.h"
#include <set>
#include <queue>
/************************************************************************/
/*Handle the Algorithm                                                                      */
/************************************************************************/
class CAntXDlg;
class AlgoritmHandler
{
public:
	AlgoritmHandler(void);
	~AlgoritmHandler(void);

public:
	float RangedRand(float range_min, float range_max);
	static void ClearAllDatas();
	static void setDefaultLineColor(Color theColor);
	static void setDefaultLineWidth(int lineWidth);
	static void setDefaultNodeColor(Color theColor);

	static void DrawLineFromNodeToNode(Graphics* graphics, NodePoint& oriNodePoint, NodePoint& disNodePoint);
	static void DrawLineFromNodeToNode(Graphics* graphics, Color theColor, NodePoint& oriNodePoint, NodePoint& disNodePoint);

	static void InitGlobalLinePairsWithNodesTable();
	static void DrawLines(Graphics* graphics);
	static bool IsPairInGlobalLinePair(NODENUM theFirst, NODENUM theSecond);
public:
	//contains all the nodes
	static vector<NodePoint> GlobalNodesTable;
	static vector<Line> GlobalLinePairs;
	static set<int> ForbiddenNodes;
	static Color DefaultLineColor;
	static int DefaultLineWidth;
private:
	static bool IsInGlobalLinePairs(Line theLine);
public:
	void DoAlgorithm();
private:
	void PreSetParams();
	bool IsInSet(set<int>& theSet, int theElement);
	NODENUM ChooseNextNode(NODENUM curNodeNum, vector<NodePoint>& theTable);
	float GetNeighbourNodesInfo(NODENUM first, NODENUM second, int type=TYPEDIS);
	void SetNeighbourNodesInfo(NODENUM first, NODENUM second, float theValue, int type=TYPEDIS);
	float CalculateNeighbourNodesProbability(NODENUM curNode, NODENUM next);//step 1
	NODENUM RouletteChoose(vector<pair<NODENUM, float>>& theCandidates);
	void VolatilizePheromone();
	void RunTheAnts();
	static CAntXDlg* getMainDlg();
private:
	set<NODENUM> mVisitedNodes;
	float mBestRoadLength;
	static queue<NODENUM> mBestRoadNodesQue;

};

#endif


